package com.woniuxy.controller;


import com.woniuxy.entity.ResponseResult;
import com.woniuxy.entity.User;

import com.woniuxy.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
public class LoginController {
    @Autowired
    LoginService loginService;
    @PostMapping("/login")
    public ResponseResult Login(@RequestBody User user, HttpServletResponse response){
//登录成功将token存入响应头中

        try{

            String token=loginService.Login(user);
            response.setHeader("token ", token);
            response.setHeader("Access-Control-Expose-Headers", "token");
            System.out.println(token);
            return new ResponseResult(200, "ok", null);

        }catch(Exception ex){
            return  new ResponseResult(405, ex.getMessage(), null);

        }



    }
}
